<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include 'includes/header.php';

$num = (int)$_GET['number'];
$number_q = mysql_query('SELECT * FROM casino WHERE casino_id="'.$num.'"');
if(!isset($_GET['number']) OR mysql_num_rows($number_q)==0){
   header('Location: index.php');
   exit;
}
$number_f = mysql_fetch_assoc($number_q);

$view_q = mysql_query('SELECT * FROM casino_view WHERE casino_id="'.$_GET['number'].'" AND user_view="'.$_SESSION['user_info']['user'].'"');
if(mysql_num_rows($view_q)==0){
    mysql_query('INSERT INTO casino_view(casino_id,user_view) VALUES("'.$_GET['number'].'","'.$_SESSION['user_info']['user'].'")');
    if(mysql_error()){
       echo 'Грешка, моля свържете се с администратор.';
    }
}
$allview_q = mysql_query('SELECT COUNT(*) as cnt FROM casino_view WHERE casino_id="'.$_GET['number'].'"');
$allview_f = mysql_fetch_assoc($allview_q);

$howfavourite_q = mysql_query('SELECT COUNT(*) as cnt FROM casino_favourite WHERE casino_id="'.$_GET['number'].'"');
$howfavourite_f = mysql_fetch_assoc($howfavourite_q);


$favourite_q = mysql_query('SELECT * FROM casino_favourite WHERE casino_id="'.$_GET['number'].'" AND user="'.$_SESSION['user_info']['user'].'"');
$check_favourite = mysql_num_rows($favourite_q);
if($_GET['add']=="favourite"){
    if(mysql_num_rows($favourite_q)==0){
        mysql_query('INSERT INTO casino_favourite(casino_id,user) VALUES("'.$_GET['number'].'","'.$_SESSION['user_info']['user'].'")');
        header('Location: casino.php?number='.$_GET['number'].'');
        exit;
    }
    else{
        header('Location: casino.php?number='.$_GET['number'].'');
        exit;
    }   
}

if($_GET['remove']=="favourite"){
    $remove_q = mysql_query('SELECT * FROM casino_favourite WHERE casino_id="'.$_GET['number'].'" AND user="'.$_SESSION['user_info']['user'].'"');
    if(mysql_num_rows($remove_q)==1){
        mysql_query('DELETE FROM casino_favourite WHERE casino_id="'.$_GET['number'].'" AND user="'.$_SESSION['user_info']['user'].'"');
        if(mysql_error()){
            header('Location: casino.php?number='.$_GET['number'].'');
            exit;
        }
        else{
            header('Location: casino.php?number='.$_GET['number'].'');
            exit;
        }
    }
}

if(isset($_GET['admin'])){
    if($number_f['by']!=$_SESSION['user_info']['user']){
        header('Location: index.php');
        exit;
    }
}
if($_GET['get']=="money"){
	$money_q = mysql_query('SELECT money FROM casino WHERE `by`="'.$_SESSION['user_info']['user'].'" AND casino_id="'.$_GET['number'].'"');
	$money_f = mysql_fetch_assoc($money_q);
	mysql_query('UPDATE users SET money=money+'.$money_f['money'].' WHERE user="'.$_SESSION['user_info']['user'].'"');
	mysql_query('UPDATE casino SET money=0 WHERE `by`="'.$_SESSION['user_info']['user'].'" AND casino_id="'.$_GET['number'].'"');
	header('Location: casino.php?number='.$_GET['number'].'&admin');
	exit;
}
my_header('Казина :: Jwakk');
?>
			<div class="line"></div>
			<div class="mainConteiner">
			
			<?php include 'includes'.DIRECTORY_SEPARATOR.'top.php'; ?>
			<div class="topDelimiter"></div>
			
			<div class="content">
			
			<table cellspacing="0" cellpadding="0" width="100%"><tr>
			
			<td class="Mainmenu" valign="top">
                            <a href="index.php"><div class="manuOnB">Казина</div></a>
                            <a href="buyCasino.php"><div class="manuB">Купи казино</div></a>
                            <a href="yoursC.php"><div class="manuB">Твои казина</div></a>
                            <a href="fight.php"><div class="manuB">Сбий се</div></a>
                            <a href="work.php"><div class="manuB">Работа</div></a>
                            <a href="zalozi.php"><div class="manuB">Залози</div></a>
                            <a href="coffee.php"><div class="manuB">Градът</div></a>
                            <a href="profile.php?user=<?php echo $_SESSION['user_info']['user']; ?>"><div class="manuB">Профил</div></a>
                            <?php
								$mes_q = mysql_query('SELECT id FROM message WHERE `do`="'.$_SESSION['user_info']['user'].'" AND `read`="0"');
								$mes_n = mysql_num_rows($mes_q);
								echo '<a href="mail.php"><div class="manuB">Съобщения ['.$mes_n.']</div></a>';
							?>
                            <a href="index.php?logout"><div class="manuBLogOut">Изход</div></a>

                            <br/>
                            <a href="#"><img alt="Последвайте Jwakk в Facebook" src="img/facebook.png" /></a>
                            <a href="#"><img alt="Последвайте Jwakk в Twitter" src="img/twitter.png" /></a>
                            <a href="#"><img alt="Абонирайте се за RSS емисии" src="img/rss.png" /></a>
                        </td>
				
				<td valign="top">
					<div class="gameBorder">
					<div class="TheGame">
					<div class="casinoTitle"><div class="casinoLevel">8<br/>ниво</div> <span>Казино :: <?php echo $number_f['name'];?></span>
                                        <?php
                                            if($check_favourite==0){
                                                echo '<a href="casino.php?number='.$_GET['number'].'&add=favourite">Добави в любими</a>';
                                            }
                                            elseif($check_favourite==1){
                                                echo '<a href="casino.php?number='.$_GET['number'].'&remove=favourite">Махни от любими</a>';
                                            }
                                        ?>
                                        </div>	
					<br />
				<?php 
				if(isset($_GET['game']))
				{
					if($_GET['game']=="roletka")
					{
						?>
						<div class="roletka">
							<small class="yellow">Число от 1 до 36:</small><br/><input type="text" class="textF2" id="zalog" /><br/>
							<small class="yellow">Залог(до $300):</small><br/><input type="text" class="textF2" id="money" /><br/><br/>
							<input type="hidden" name="casino" value="<?php echo $_GET['number']; ?>" id="casino" />
							<button  class="but" onclick="roll()" >Залагай</BUTTON>
							<a href="casino.php?number=<?php echo $_GET['number']; ?>" class="but">Назад</a>
						</div>
						<?php
					}
					elseif($_GET['game']=="rutativka")
					{
						
					}
					elseif($_GET['game']=="zar")
					{
						?>
							<small class="yellow">Число от 2 до 12:</small><br/><input type="text" class="zar"  />
							<button  class="but" onclick="zar()" >Залагай</BUTTON> <a href="casino.php?number=<?php echo $_GET['number']; ?>" class="but">Назад</a>
							<div class="zarowe" ></div>
						<?
					}
				}
				
				
                                elseif(isset($_GET['admin'])){
                                    
                                    if(isset($_GET['money'])){
                                        
                                    }
                                    $forcasino_q = mysql_query('SELECT * FROM casino WHERE casino_id="'.$_GET['number'].'"');
                                    $forcasino_f = mysql_fetch_assoc($forcasino_q);
                                    echo '
                                    <a href="#" class="tab">Информация за казиното</a> <a href="#" class="tab">Достъп</a>  <a href="#" class="tab">Игри</a> 
					<div class="del"></div>
					<div class="casinostat">Ниво: 8</div>
					<div class="casinostat">Печалба: '.$forcasino_f['money'].'$ <span style="float: right;"><a href="casino.php?number='.$_GET['number'].'&admin&get=money">Изтегли Печалбата</a></span></div>
					<div class="casinostat">Посещения: '.$allview_f['cnt'].' <span style="float: right;"><a href="#">Увеличи посещенията си</a></span></div>
					<div class="casinostat">В любими: '.$howfavourite_f['cnt'].'</div>
					
					<br/>
                                    ';
                                }
					elseif(isset($_GET['football'])){
						?>
						<div class="casinostat"> <a href="#" class="zalog">Левски </a> &nbsp;vs&nbsp; <a href="#" class="zalog">ЦСК </a></div>
						<div class="casinostat"> <a href="#" class="zalog">Локо Мездра </a> &nbsp;vs&nbsp; <a href="#" class="zalog">Локо Пловдив </a></div>
						<div class="casinostat"> <span href="#" class="zalog">Барселона</span> &nbsp;vs&nbsp; <span href="#" class="zalojil"> &nbsp;Милан</span></div>
						<div class="casinostat"> <a href="#" class="zalog">Локо София </a> &nbsp;vs&nbsp; <a href="#" class="zalog">Локо Бургас </a></div>
						<div class="casinostat"> <span href="#" class="zalojil"> &nbsp;Манчестър Юнайтед</span> &nbsp;vs&nbsp; <span href="#" class="zalog">Манчестър Сити </span></div>
						<div class="casinostat"> <a href="#" class="zalog">Локо София </a> &nbsp;vs&nbsp; <a href="#" class="zalog">Локо Бургас </a></div>
						<div class="casinostat"> <a href="#" class="zalog">Локо Стара Загора </a> &nbsp;vs&nbsp; <a href="#" class="zalog">Локо Ямбол </a></div>
						<div class="casinostat"> <a href="#" class="zalog">ФК Тунджа </a> &nbsp;vs&nbsp; <a href="#" class="zalog">Барселона </a></div>
						
						<div class="access">Печалбите от мачовете ще бъдат изчислени на 15.11.2011 (утре).</div>
						<?php
					}
				else
				{
				?>
					<table width="100%"><tr align="center">
					
						<td> <div class="gameTo"><a href="#">
							<img src="img/rotativka.png" class="gameAA" alt="Jwakk" title="Ротативка"/>  <span>Ротативка</span>
						</a></div> </td>
						<td> <div class="gameTo"><a href="casino.php?number=<?php echo $_GET['number'] ; ?>&game=roletka">
							<img src="img/roletka.png" class="gameAA" alt="Jwakk" title="Ролетка"/>  <span>Ролетка</span>
						</a></div> </td>
						<td> <div class="gameTo"><a href="casino.php?number=<?php echo $_GET['number'] ; ?>&game=zar">
							<img src="img/zarove.png" class="gameAA" alt="Jwakk" title="Зарове"/>  <span>Зарове</span>
						</a></div> </td>
					</tr></table>
				<?php
				}
				
                                            if($number_f['by']==$_SESSION['user_info']['user'] AND !isset($_GET['admin'])){
                                                echo '<div class="overLevel">Можеш да влезеш в админ панела на казиното от <a href="casino.php?number='.$_GET['number'].'&admin">тук</a></div>';
                                            }
                                            elseif(isset($_GET['admin'])){
                                                echo '<div class="overLevel"><a href="casino.php?number='.$_GET['number'].'">Начало</a></div>';
                                            }
                                            
                                            if(!isset($_GET['admin'])){
                                                ?>
                                            <div class="casinoinfa">Собственост на: <?php echo $number_f['by']; ?> | В любими: <?php echo $howfavourite_f['cnt']; ?> | Посещения: <?php echo $allview_f['cnt']; ?> </div>
                                                <?php
                                            }
                                        ?>
					<br/>
					
					<!--<div class="load"> <div></div> </div>
					<span class="loadText">До казино ниво <b>6</b> остават 63%</span><br/><br/>-->
					
					</div>
					</div>
					<div class="help"> <a href="#">Помощ</a> | <a href="#">FAQ</a> | <a href="#">Условия</a> | <a href="#">Facebook</a></div>
				</td>
			
			</tr></table>
			
			
			<div class="footer">
				© JwakK.com · Всички права запазени · <a href="#">Условия за ползване</a>
			</div>
			</div>
			</div>
			
			<div class="bottom"></div>
			
			</body>
			</html>